/**
 * 我的资料
 * author:zhangjlt
 * date:2016年3月10日10:30:42
 */
;
define(function(require, exports, module) {
	var wechat = require("wechat");
	var template = require("template");
	var equity = {
		data: {},
		/**
		 * bindEvent 页面事件
		 */
		bindEvent: function() {
	//返回
			$("#return_equity").unbind().on("click",function(){
				window.location.href="#home";
			});
		},
		/**
		 * 进行页面路由监听配置
		 */
		bindRout: function() {
			//公共页面监听路由
			Path.map("#/index/:page_name").to(function() {
				console.log(this.params["page_name"]);
				var page_name = this.params["page_name"];
				//记录状态
				common.loadPage({
					pageUrl: "html/" + page_name + ".html",
					reload: true,
					from: "right"
				});
			});
			Path.map("#home").to(function() {
				//返回首页
				common.loadPage({
					pageUrl: "html/index.html",
					reload: false,
					from: "left"
				});
			});
			//Path.root("#home");
			Path.listen();
		},
		/**
		 * 页面数据加载
		 */
		initData: function() {
			var param = {
				"openId": window.localStorage.getItem("openId"),
				"appId": window.localStorage.getItem("appId"),
			};
			common.loadData({
				url: "/wxmember/service/getEquity",
				param: param,
				successCallBack: equity.getEquityCallBack, //回调函数
				dataSource: "getEquity"
			});

			//iscroll滚动加入
			var iscroll = require("iscroll");
			common.initIscroll({
				container: "iscrollContent_equity",
				showScrollBar: false
			});

		},
		//callback function
		getEquityCallBack: function(json) {
			console.log("调用后台ajax返回值为：" + JSON.stringify(json));
			if(json.status == "0") {
				var rights = json.data.rights.split("；");
				var instructions = json.data.instructions.split("；");
				equity.data.rights=rights;
				equity.data.instructions = instructions;
				var html = template('equityTemplate', equity.data);
				document.getElementById('main_equity').innerHTML = html;
				
			} else {
				var window_height = document.documentElement.clientHeight;
				$("#main_equity").height(window_height-$(".header").height()-$(".qy_banner").height());
				common.show_nodata("未查询到权益信息","main_equity");
				common.showTip({
					content:json.message
				});
			}
		},
		/**
		 * each page init mothed
		 */
		initialize: function() {
			//动态加载数据
			equity.initData();
			//事件绑定
			equity.bindEvent();
			//路由绑定
			equity.bindRout();
		}
	};

	module.exports = equity;
});